﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using cds_betadev01.source;

namespace cds_betadev01.source
{
    
    class FreeView
    {
        private int interval; 
        public float angularSpeed = 10f;
        public float translationSpeed = 10f;
        public float zoomSpeed = 10f;
        private Vector3 direction;
        public Keys Front = Keys.Space;
        public Keys Back = Keys.LeftAlt;
        public Keys Left = Keys.NumPad4;
        public Keys Right = Keys.NumPad6;
        public Keys TurnUp = Keys.NumPad8;
        public Keys TurnDown = Keys.NumPad5;
        public Keys TurnLeft = Keys.NumPad7;
        public Keys TurnRight = Keys.NumPad9;
        public Keys Zoom = Keys.NumPad2;
        public Keys UnZoom = Keys.NumPad0;
        public Keys Up = Keys.Z;
        public Keys Down = Keys.S;

        public Camera front(Camera cam)
        {
            cam.setWorld(Matrix.CreateTranslation(Vector3.Forward * translationSpeed * interval)*cam.getWorld());
            return cam;
        }
        public Camera back(Camera cam)
        {
            cam.setWorld(Matrix.CreateTranslation(Vector3.Backward * translationSpeed * interval) * cam.getWorld());
            return cam;
        }
        public Camera left(Camera cam)
        {
            cam.setWorld(Matrix.CreateTranslation(Vector3.Left * translationSpeed * interval) * cam.getWorld());
            return cam;
        }
        public Camera right(Camera cam)
        {
            cam.setWorld(Matrix.CreateTranslation(Vector3.Right * translationSpeed * interval) * cam.getWorld());
            return cam;
        }
        public Camera up(Camera cam)
        {
            cam.setWorld(Matrix.CreateTranslation(Vector3.Up * translationSpeed * interval) * cam.getWorld());
            return cam;
        }
        public Camera down(Camera cam)
        {
            cam.setWorld(Matrix.CreateTranslation(Vector3.Down * translationSpeed * interval) * cam.getWorld());
            return cam;
        }
        public Camera turnUp(Camera cam)
        {
            cam.rotate(Vector3.Up * angularSpeed * interval);
            return cam;
        }
        public Camera turnDown(Camera cam)
        {
            cam.rotate(Vector3.Down * angularSpeed * interval);
            return cam;
        }
        public Camera turnLeft(Camera cam)
        {
            cam.rotate(Vector3.Left * angularSpeed * interval);
            return cam;
        }
        public Camera turnRight(Camera cam)
        {
            cam.rotate(Vector3.Right * angularSpeed * interval);
            return cam;
        }
        public Camera zoom(Camera cam)
        {
            cam.setFovy(cam.getFovy() + zoomSpeed * interval);
            return cam;
        }
        public Camera unZoom(Camera cam)
        {
            cam.setFovy(cam.getFovy() - zoomSpeed * interval);
            return cam;
        }

        public Camera Upload(KeyboardState kkstate, Camera cam) // cam is used as Global parameter
        {
            

            if (kkstate.IsKeyDown(Front))
            {
               cam = front(cam);
            }
            if (kkstate.IsKeyDown(Back))
            {
                cam = back(cam);
            }
            if (kkstate.IsKeyDown(Left))
            {
                cam = left(cam);
            }
            if (kkstate.IsKeyDown(Right))
            {
                cam = right(cam);
            }
            if (kkstate.IsKeyDown(TurnUp))
            {
                cam = turnUp(cam);
            }
            if (kkstate.IsKeyDown(TurnDown))
            {
                cam = turnDown(cam);
            }
            if (kkstate.IsKeyDown(TurnLeft))
            {
                cam = turnLeft(cam);
            }
            if (kkstate.IsKeyDown(TurnRight))
            {
                cam = turnRight(cam);
            }
            if (kkstate.IsKeyDown(Down))
            {
                cam = down(cam);
            }
            if (kkstate.IsKeyDown(Up))
            {
                cam = up(cam);
            }
            if (kkstate.IsKeyDown(Zoom))
            {
                cam = zoom(cam);
            }
            if (kkstate.IsKeyDown(UnZoom))
            {
                cam = unZoom(cam);
            }

            return cam;
        }
        
    }
}
